package com.service.Impl;

import com.entity.Notification;
import com.exception.GlobalException;
import com.mapper.NotificationMapper;
import com.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: NotificationServiceImpl
 * Description:
 *
 * @author L_Z_R
 * @version 1.0
 * @create 2025/06/18 09:12
 */
@Service
public class NotificationServiceImpl implements NotificationService {
    @Autowired
    private NotificationMapper notificationMapper;
    @Override
    public void insert(Notification notification) {
        try {
            notificationMapper.insert(notification);
        } catch (Exception e) {
            throw new GlobalException(1001,"插入通知失败");
        }
    }

    @Override
    public List<Notification> selectByType(Integer receiverId, byte type) {
        try {
            return notificationMapper.selectByType(receiverId, type);
        } catch (Exception e) {
            e.printStackTrace();
            throw new GlobalException(1001,"查询通知失败");
        }
    }

    @Override
    public int countUnreadByUserId(Integer receiver_id) {
        try {
            return notificationMapper.countUnreadByUserId(receiver_id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new GlobalException(1001,"查询未读通知失败");
        }
    }
}
